(function() {
  app.service('getPhoneType', function(tradeApi, $q, $window) {
    var that = this;

    this.get = function() {
      //获取手机型号函数begin
      //正则,忽略大小写
      var pattern_phone = new RegExp("iphone", "i");
      var pattern_android = new RegExp("android", "i");
      var userAgent = navigator.userAgent.toLowerCase();
      var isAndroid = pattern_android.test(userAgent);
      var isIphone = pattern_phone.test(userAgent);
      var phoneType = "phoneType";
      if (isAndroid) {
        var zh_cnIndex = userAgent.indexOf("-");
        var spaceIndex = userAgent.indexOf("build", zh_cnIndex + 4);
        var fullResult = userAgent.substring(zh_cnIndex, spaceIndex);
        phoneType = fullResult.split(";")[1];
      } else if (isIphone) {
        var height = window.screen.availHeight;
        if (height == 812) {
          phoneType = "iphonex";
        }
      } else {
        phoneType = "未知设备";
      }
      return {
        type: phoneType,
        css: {
          width: '100%',
          height: '0.5rem',
          background: '#efefef',
          position: 'fixed',
          left: 0,
          bottom: 0
        }
      }
    }
    this.config = that.get();
  });
})();